﻿using System;
using System.Xml;
using System.Xml.XPath;
using FeedsLibrary.Feeds.Abstract;

namespace FeedsLibrary.Feeds.Atom
{
    internal class AtomItem : AbstractItem
    {
        public AtomItem(string domain, IXPathNavigable nodeItem, DateTime lastBuildDate)
        {
            _lastBuildDate = lastBuildDate;
            LoadStandardAttributes( domain, nodeItem );
            FeedSpecificAttributes( nodeItem );
        }

        public override void FeedSpecificAttributes(IXPathNavigable nodeItem2)
        {
            XmlNode nodeItem = nodeItem2 as XmlNode;

            if (nodeItem["content"] != null)
            {
                Description = nodeItem[ "content" ].InnerText;
            }

            if ( nodeItem[ "published" ] != null )
            {
                string strDate = nodeItem[ "published" ].InnerText;
                PubDate = GetDate( strDate );
            }
            else
            {
                PubDate = _lastBuildDate;
            }

            if ( nodeItem[ "id" ] != null )
            {
                Guid = ( nodeItem[ "id" ].InnerText );
            }

            if ( nodeItem[ "link" ] != null )
            {
                Link = nodeItem[ "link" ].Attributes[ "href" ].Value;
            }
        }
    }
}